﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMaster.Master" AutoEventWireup="true" CodeBehind="House.aspx.cs" Inherits="MonitorPlan.Admin.House" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>House Management</title>
    <script>
        $(document).ready(function () {
            $("a#btnHouse").css("background", "#CCC");
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:SqlDataSource ID="s1" runat="server" SelectCommand="select house.houseid, house.housename, house.description, location.locationname,concat(users.firstname,' ', users.lastname) as [owner] from house inner join location on house.locationid = location.locationid inner join users on users.userid=house.userid and house.isdeleted=0"
            ConnectionString="<%$ ConnectionStrings:conStr %>"></asp:SqlDataSource>
        <asp:SqlDataSource ID="s2" runat="server" SelectCommand="select locationid, locationname from location where isdeleted=0"
             ConnectionString="<%$ ConnectionStrings:conStr %>"></asp:SqlDataSource>
        <asp:SqlDataSource ID="s3" runat="server" SelectCommand="select userid, concat(firstname, ' ',lastname) as owner from users where isdeleted=0"
              ConnectionString="<%$ ConnectionStrings:conStr %>"></asp:SqlDataSource>
        
             <ul class="nav nav-pills action-buttons">
                <li><asp:LinkButton ID="btnView" runat="server" OnClick="btnView_Click">
                    <i class="icon icon-view"></i>&nbsp;View</asp:LinkButton></li>
                 <li>
                     <asp:LinkButton ID="btnAdd" runat="server" OnClick="btnAdd_Click">
                         <i class="icon icon-add"></i>&nbsp;Add New
                     </asp:LinkButton>
                 </li>
            </ul>
            <asp:MultiView ID="mv" runat="server" ActiveViewIndex="0">

                <%--This is the default view--%>
                <asp:View ID="vView" runat="server">
                    <h5 class="text-info">View Houses</h5>
                    <asp:Repeater ID="rp1" runat="server" DataSourceID="s1" OnItemCommand="rp1_ItemCommand">
                        <HeaderTemplate>
                            <table class="table table-condensed table-striped table-hover">
                                <tr>
                                    <th>House Id</th>
                                    <th>House Name</th>
                                    <th>Description</th>
                                    <th>Location</th>
                                    <th>House Owner</th>
                                    <th>Actions</th>
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td><%# Eval("houseid") %></td>
                                <td><%# Eval("housename") %></td>
                                <td><%# Eval("description") %></td>
                                <td><%# Eval("locationname") %></td>
                                <td><%# Eval("owner") %></td>
                                <td>
                                     <asp:LinkButton ID="btnDetail" runat="server"
                                        CommandName="detail" CommandArgument='<%# Eval("houseid") %>'>
                                        Detail</asp:LinkButton> 
                                     <asp:LinkButton ID="btnEdit" runat="server" 
                                        CommandName="edit" CommandArgument='<%# Eval("houseid") %>'>
                                        Edit</asp:LinkButton> 
                                    <asp:LinkButton ID="btnDelete" runat="server"
                                        CommandName="delete" CommandArgument='<%# Eval("houseid") %>' OnClientClick="return confirm('You want to delete it?');">
                                        Delete
                                    </asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                    </asp:Repeater>
                </asp:View>
            <%-- view for add new house --%>
                <asp:View ID="vNew" runat="server">
                    <h5 class="text-info">Add New House</h5>
                    <label for="txtHouseName">House Name</label>
                    <asp:TextBox ID="txtHouseName" runat="server" Width="360"></asp:TextBox>
                    <label for="txtHoseLocation">Location</label>
                    <asp:DropDownList ID="txtHouseLocation" runat="server" DataSourceID="s2" AutoPostBack="false"
                        DataTextField="locationname" DataValueField="locationid" Width="310">
                    </asp:DropDownList>
                    <asp:LinkButton ID="btnAddLocation" runat="server" CssClass="btn btn-link" OnClick="btnAddLocation_Click">
                        <i class="icon-map-marker"></i> New</asp:LinkButton>
                    <label for="txtHouseOwner">Owner Name</label>
                    <asp:DropDownList ID="txtHouseOwner" runat="server" AutoPostBack="false" Width="310" DataSourceID="s3"
                         DataTextField="owner" DataValueField="userid">

                    </asp:DropDownList>
                    <asp:LinkButton ID="btnAddOwner" runat="server" CssClass="btn btn-link">
                        <i class="icon-map-marker"></i> New
                    </asp:LinkButton>
                    <label for="txtHouseDescription">Description</label>
                    <asp:TextBox ID="txtHouseDescription" runat="server" TextMode="MultiLine" Width="360" Height="60"></asp:TextBox>
                    <br />
                    <asp:LinkButton ID="btnSave" runat="server" CssClass="btn btn-primary btn-small" OnClick="btnSave_Click">
                        <i class="icon-ok-circle icon-white"></i> Save</asp:LinkButton>
                    <asp:LinkButton ID="btnCancel" runat="server" CssClass="btn btn-danger btn-small" OnClick="btnCancel_Click">
                        <i class="icon-remove-sign icon-white"></i> Cancel</asp:LinkButton>
                    <asp:LinkButton ID="btnClose" runat="server" CssClass="btn btn-success btn-small" OnClick="btnClose_Click">
                        <i class="icon-arrow-left icon-white"></i> Back</asp:LinkButton>
                    <br /><br />
                    <div runat="server" id="actionSms"></div>
                </asp:View>

                <%--view detail house information--%>
                <asp:View ID="vDetail" runat="server">
                    <h5 class="text-info">View Detail House</h5>
                  <table class="tbl">
                      <tr>
                          <th>House Id</th>
                          <td style="width: 40px;">&nbsp;:</td>
                          <td><asp:Label ID="lbHouseId" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <th>House Name</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbHouseName" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <th>Description</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbHouseDescription" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                       <tr>
                          <th>Owner Name</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbOwnerName" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                       <tr>
                          <th>Location Name</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbLocationName" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <th>Is Deleted</th>
                          <td>&nbsp;:</td>
                          <td><asp:Label ID="lbIsDeleted" runat="server" CssClass="text-info"></asp:Label></td>
                      </tr>
                      <tr>
                          <td></td>
                          <td></td>
                          <td></td>
                      </tr>
                      <tr>
                          <td>
                              <asp:LinkButton ID="btnBack" runat="server" CssClass="btn btn-success btn-small" OnClick="btnBack_Click">
                                  <i class="icon-arrow-left icon-white"></i> Back</asp:LinkButton>
                          </td>
                          <td></td>
                          <td></td>
                      </tr>
                  </table>
                </asp:View>
                <%-- view to edit a house --%>
                <asp:View ID="vEdit" runat="server">
                    <h5 class="text-info">Update House</h5>
                    <asp:HiddenField ID="txtid" runat="server" />
                    <label for="txtHname">House Name</label>
                    <asp:TextBox ID="txtHname" runat="server" Width="360"></asp:TextBox>
                    <label for="txtOwnerName">Owner Name</label>
                    <asp:DropDownList runat="server" ID="txtOwnerName" AutoPostBack="false" Width="310" DataSourceID="s3"
                         DataTextField="owner" DataValueField="userid"></asp:DropDownList>
                    <asp:LinkButton ID="btnNewOwner" runat="server" CssClass="btn btn-link">
                        <i class="icon-map-marker"></i> New
                    </asp:LinkButton>
                    <label for="txtLocation">House Location</label>
                    <asp:DropDownList ID="txtLocation" runat="server" AutoPostBack="false" Width="310" DataSourceID="s2"
                         DataTextField="locationname" DataValueField="locationid">

                    </asp:DropDownList>
                    <asp:LinkButton ID="btnNewLocation" runat="server" CssClass="btn btn-link" OnClick="btnNewLocation_Click">
                        <i class="icon-map-marker"></i> New
                    </asp:LinkButton>
                    <label for="txtHDescription">Description</label>
                    <asp:TextBox ID="txtHDescription" runat="server" TextMode="MultiLine" Width="360" Height="60"></asp:TextBox>
                     <br />
                    <asp:LinkButton ID="btnUpdate" runat="server" CssClass="btn btn-primary btn-small" OnClientClick="return confirm('You want to update?')" OnClick="btnUpdate_Click">
                        <i class="icon-ok-circle icon-white"></i> Update</asp:LinkButton>
                    <asp:LinkButton ID="btnCancelUpdate" runat="server" CssClass="btn btn-danger btn-small" OnClick="btnCancelUpdate_Click">
                        <i class="icon-remove-sign icon-white"></i> Cancel</asp:LinkButton>
                    <div id="updateSms" runat="server"></div>
                </asp:View>
            </asp:MultiView>

        </ContentTemplate>
    </asp:UpdatePanel>
    
</asp:Content>
